package uk.ac.durham.tel.synergynet.covanto.workspace;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IStatus;

public class WorkspaceResourceHelper {
	public static boolean isProjectNameValid(String name) {
		IWorkspace workspace = ResourcesPlugin.getWorkspace();
		IStatus nameStatus = workspace.validateName(name,
                IResource.PROJECT);
        return nameStatus.isOK();
	}
	
	public static boolean isProjectExistInWorkspace(String name) {
		IProject project = getProjectHandle(name);
		return project.exists();
	}
	
	private static IProject getProjectHandle(String name) {
		return ResourcesPlugin.getWorkspace().getRoot().getProject(name);
	}
}
